<template>
    <div class="main-content clearfix">
        <div class="instructions">个人信息</div>
        <img v-lazy="'./images/portrait1.jpg'" />
        <form action="javascript:">
            <ul class="message">
                <li class="clearfix">
                    <div class="label">用户名：</div>
                    <input type="text" class="information name" v-model="account.userName" autocomplete="off" />
                </li>
                <li class="clearfix">
                    <div class="label">ID:</div>
                    <input type="text" class="information ID" v-model="account.accountId" autocomplete="off" readonly />
                </li>
                <li class="clearfix">
                    <div class="label">性别：</div>
                    <div class="sex">
                        <!-- <input type="radio" name="sex" :checked="account.gender == '男'"  value="男" v-model="account.gender"/>男
                        <input type="radio" name="sex" :checked="account.gender == '女'"  value="女" v-model="account.gender"/>女 -->
                        <input type="radio" name="sex"  value="男" v-model="account.gender"/>男
                        <input type="radio" name="sex"  value="女" v-model="account.gender"/>女
                    </div>
                </li>
                <li class="clearfix">
                    <div class="label">年龄：</div>
                    <input type="text" class="information age" v-model="account.age" autocomplete="off" />
                </li>
                <li class="clearfix">
                    <div class="label">地区：</div>
                    <input type="text" class="information region" v-model="account.address" autocomplete="off" />
                </li>
                <li class="clearfix">
                    <div class="label">个性签名：</div>
                    <textarea class="information signature" maxlength="35" autocomplete="off" v-model="account.signature"></textarea>
                </li>
            </ul>
            <input type="submit" value="提交" class="button" @click.prevent="editUserInfo"/>
        </form>
    </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
    data() {
        return {
            account: {},
        };
    },
    mounted() {
        this.account = Object.assign({},this.userInfo);
    },
    computed:{
        ...mapState("user",["userInfo"])
    },
    methods: {
        async editUserInfo(){
            let data = Object.assign({},this.account);
            data.accountId = undefined;
            console.log(data);
            try {
                await this.$store.dispatch("user/editUserInfo",data)
                this.$message({
                    message:"修改个人信息成功！",
                    type:"success"
                })
            } catch (error) {
                this.$message({
                    message:error,
                    type:"error"
                })
            }
        }
    },
};
</script>

<style scoped>
/*设置详情页面的样式*/

/*设置修改个人信息栏*/
.main-content {
    margin-top: 20px;
    width: 1040px;
    min-height: 600px;
    background-color: rgba(255, 255, 255, 0.8);
}
/*设置头标*/
.main-content .instructions {
    width: 980px;
    padding-bottom: 20px;
    margin: 30px auto;
    border-bottom: 2px solid rgba(91, 81, 69, 0.4);
}
/*修改头像大小样式*/
.main-content img {
    width: 150px;
    height: 150px;
    border-radius: 25%;
    margin: 80px 150px 0 0;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    float: right;
}
/*修改表单位置*/
.main-content form {
    float: left;
    margin: 100px 0 100px 200px;
    padding: 50px;
    border: 2px solid rgba(91, 81, 69, 0.4);
}

/*修改表单数据的排列*/
.main-content form li {
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 15px;
}

.main-content form li .label,
.main-content form li .information {
    float: left;
}
/*修改label的样式让输入框对齐*/
.main-content form li .label {
    width: 80px;
    margin-top: 3px;
}

/*修改input组件的样式*/
.main-content form li .information {
    width: 240px;
    height: 30px;
    color: rgba(91, 81, 69, 0.8);
    font-size: 15px;
    line-height: 30px;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    outline: none;
    background-color: transparent;
}

.main-content form li .sex {
    float: left;
    font-size: 15px;
    line-height: 30px;
    margin-top: 3px;
}

.main-content form li .sex input:last-child {
    margin-left: 16px;
}

.main-content form li .signature {
    border: 1px solid rgba(0, 0, 0, 0.2);
    resize: none;
    height: 90px;
}

.main-content form .information:hover {
    border-color: rgb(193, 193, 193);
}

.main-content form .information:focus {
    color: rgb(91, 81, 69);
    border-color: rgb(91, 81, 69);
}

.main-content form .button {
    border: none;
    width: 100px;
    height: 40px;
    display: block;
    background-image: linear-gradient(
        to top,
        rgb(72, 62, 50),
        rgb(172, 180, 178)
    );
    color: white;
    font-size: 16px;
    line-height: 30px;
    margin: 20px auto 0;
    box-shadow: 0 0 5px rgba(72, 62, 50, 0.3);
}

.main-content form .button:hover {
    background-image: linear-gradient(
        to top,
        rgb(96, 82, 70),
        rgb(192, 203, 200)
    );
}

.main-content form .button:active {
    background-image: linear-gradient(
        to top,
        rgb(85, 77, 60),
        rgb(182, 185, 190)
    );
}
</style>